<template>
	<view>
		<view class="item" v-for="(res, index) in siteList" :key="res.id">
			<view class="left" @click="exchange(res.id)">
				<view class="top">
					<view class="name">{{ res.name }}</view>
					<view class="phone">{{ res.phone }}</view>
					<view class="tag">
						<!-- <text v-for="(item, index) in res.tag" :key="index" :class="{ red: item.tagText == '默认' }">{{ item.tagText }}</text> -->
					</view>
				</view>
				<view class="bottom">
					{{ res.site }}
					<!-- <u-icon name="edit-pen" :size="40" color="#999999"></u-icon> -->
				</view>
			</view>
				<u-icon name="trash" :size="40" color="#999999" class="delete_icon" @click.self="showPop(res.id)"></u-icon>
		</view>
		<view class="addSite" @tap="toAddSite">
			<view class="add">
				<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>
				新建收货地址
			</view>
		</view>
		<view class="empty_box" v-if="siteList.length == 0"><u-empty text="没有收货地址" mode="address"></u-empty></view>
		<u-modal v-model="show" :content="content" @confirm="delAdd" confirm-color="#DA251D" :show-cancel-button="true"></u-modal>
		<u-modal v-model="exchangeShow" :content="exchangeContent" @confirm="exchangeGift" confirm-color="#DA251D" :show-cancel-button="true"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			siteList: [],
			show: false,
			exchangeShow: false,
			content: '确定删除该地址吗?',
			exchangeContent: '确定使用该地址?',
			delId: null,
			exchangeId: null
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		getData() {
			this.siteList = [
				{
					id: 1,
					name: '游X',
					phone: '183****5523',
					tag: [
						{
							tagText: '默认'
						}
					],
					site: '广东省深圳市宝安区 自由路66号'
				},
				{
					id: 2,
					name: '李XX',
					phone: '183****5555',
					tag: [],
					site: '广东省深圳市宝安区 翻身路xx号'
				},
				{
					id: 3,
					name: '王YY',
					phone: '153****5555',
					tag: [],
					site: '广东省深圳市宝安区 平安路13号'
				}
			];
		},
		toAddSite() {
			uni.navigateTo({
				url: '../addSite/addSite'
			});
		},
		delAdd() {
			this.siteList.map((item, index) => {
				if (item.id == this.delId) {
					this.siteList.splice(index, 1);
				}
			});
		},
		showPop(id) {
			this.show = true
			this.delId = id
		},
		exchange(id) {
			this.exchangeShow = true
			this.exchangeId = id
		},
		exchangeGift() {
			this.siteList.map((item, index) => {
				if (item.id == this.exchangeId) {
					console.log(item)
				}
			});
		}
	},
	onShow() {
		console.log(1)
	}
};
</script>

<style lang="scss" scoped>
.item {
	padding: 40rpx 20rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.top {
		display: flex;
		font-weight: bold;
		font-size: 34rpx;
		.phone {
			margin-left: 60rpx;
		}
		.delete_icon {
			margin-left: auto;
			flex: 1;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color: rgb(49, 145, 253);
			}
			.red {
				background-color: $red;
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;
	}
}
.addSite {
	display: flex;
	justify-content: space-around;
	width: 600rpx;
	line-height: 100rpx;
	position: absolute;
	bottom: 30rpx;
	left: 80rpx;
	background-color: $red;
	border-radius: 60rpx;
	font-size: 30rpx;
	.add {
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon {
			margin-right: 10rpx;
		}
	}
}

.empty_box {
	width: 100%;
	height: 70vh;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	image {
		width: 186upx;
		height: 196upx;
		margin-bottom: 45upx;
	}
	text {
		font-size: 24upx;
		color: $color-666;
		margin-bottom: 58upx;
	}
	.btn {
		font-size: 30upx;
		color: #ffffff;
		padding: 15upx 53upx;
		border-radius: 8upx;
		background: #373846;
	}
}
</style>
